From: Rafał Miłecki Date: Fri, 26 Nov 2021 16:17:08 +0000 (+0100) Subject: oseama: support extracting entity to stdout X-Git-Url: http://git.openwrt.org/%22http:/oss.oetiker.ch/rrdtool//%22/%22http:/oss.oetiker.ch/rrdtool/%22?a=commitdiff_plain;h=0fbc13572cfbd8790faaf8299309204e05a1de62;p=project%2Ffirmware-utils.git oseama: support extracting entity to stdout This allows using oseama in a pipe. It's very useful for writing data to flash using e.g. oseama extract firmware.bin -e 0 | mtd write - firmware Signed-off-by: Rafał Miłecki --- diff --git a/src/oseama.c b/src/oseama.c index d3eb9b9..f68d7d0 100644 --- a/src/oseama.c +++ b/src/oseama.c @@ -525,10 +525,6 @@ static int oseama_extract(int argc, char **argv) { fprintf(stderr, "No entity specified\n"); err = -EINVAL; goto out; - } else if (!out_path) { - fprintf(stderr, "No output file specified\n"); - err = -EINVAL; - goto out; } seama = oseama_open(seama_path, "r"); @@ -538,11 +534,15 @@ static int oseama_extract(int argc, char **argv) { goto out; } - out = fopen(out_path, "w"); - if (!out) { - fprintf(stderr, "Couldn't open %s\n", out_path); - err = -EACCES; - goto err_close_seama; + if (out_path) { + out = fopen(out_path, "w"); + if (!out) { + fprintf(stderr, "Couldn't open %s\n", out_path); + err = -EACCES; + goto err_close_seama; + } + } else { + out = stdout; } bytes = fread(&hdr, 1, sizeof(hdr), seama); @@ -558,7 +558,8 @@ static int oseama_extract(int argc, char **argv) { oseama_extract_entity(seama, out); err_close_out: - fclose(out); + if (out != stdout) + fclose(out); err_close_seama: oseama_close(seama); out: